import { unInstance } from '@/service'
import { useAuthStore } from '@/store'

interface RESPONSE {
  status: string
  message: string
  data: any
}

export default {
  /* MP0024 不登录通过手机号获取商户号或门店号列表，登录用 */
  getMerchantList(data) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/mcht/getMerchantList`,
      Object.assign(data, {
        sessionid: sessionid.value,
        source: "MT_MP",
      })
    );
  },
  /* 商户静默登录 */
  loginAndQuery(data) {
    const { openid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/mcht/loginAndQuery`,
      Object.assign(data, {
        openid: openid.value,
        source: "MT_MP",
      })
    );
  },
  /* 公告查询 */
  getNotice() {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/mcht/notice`, {
      sessionid: sessionid.value,
    });
  },
  /* 订单列表页查询 */
  getSumOrders(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/sumQuery`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* 订单查询 */
  getOrders(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/query`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 对账单列表查询
  sumGetStatement(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/sumGetStatement`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 对账单详情查询
  getStatement(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/getStatement`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 统计列表查询
  sumPageStatement(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/sumPageStatement`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 统计详情查询
  mchtStatement(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/mchtStatement`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* 数币订单列表页查询 */
  ecnySumQuery(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/ecnySumQuery`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* 数币订单查询 */
  ecnyQuery(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/ecnyQuery`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 数币对账单列表查询
  ecnySumGetStatement(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/ecnySumGetStatement`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 数币对账单详情查询
  ecnyGetStatement(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/ecnyGetStatement`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* 订单退货流水查询 */
  getRefundTransactions(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/getRefundTransactions`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* 订单退货 */
  refund(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/refund`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  getDetail(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/mcht/getDetail`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  getMchtStoreList() {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/mcht/mchtAndStoreList`, {
      sessionid: sessionid.value,
    });
  },
  changeCount(id: string, type: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/mcht/changeCount`, {
      sessionid: sessionid.value,
      merchantId: id,
      type,
    });
  },
  getDeviceList(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/device/getDeviceList`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  getSNList(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/device/getSNList`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  submitLossReport(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/mcht/submitLossReport`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // staff
  getStaffList(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/staff/getList`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  getQrcodeList(mchtNo: string, employeeNo: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/qrcode/getList`, {
      sessionid: sessionid.value,
      mchtNo,
      employeeNo,
    });
  },
  addStaff(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/staff/add`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  updateStaff(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/staff/update`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  deleteStaff(mchtNo: string, employeeNo: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/staff/delete`, {
      sessionid: sessionid.value,
      mchtNo,
      employeeNo,
    });
  },
  unbindQrcode(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/qrcode/unbind`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  bindQrcode(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/qrcode/bind`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // store
  getStoreList(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/store/getList`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  closeStore(mchtNo: string, storeId: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/store/close`, {
      sessionid: sessionid.value,
      mchtNo,
      storeId,
    });
  },
  /* MP0077 门店详情查询 */
  getStoreInfo(storeId: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/store/info`, {
      sessionid: sessionid.value,
      storeId,
    });
  },
  /* MP0059 门店新增信息获取 */
  getStoreInfoForNew(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/store/getStoreInfo`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  submitStore(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/store/submit`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  submitUpdateStore(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/store/updateSubmit`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 设置消息推送开关
  setPushSwitch(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/notify/setPushSwitch`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 商户信息/门店列表查询
  getMerchantInfoList(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/mcht/getMerchantInfoList`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  // 授权码
  /* MP0074 授权码员工列表查询 */
  getStaffListWithAuthCode() {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/authcode/getStaffListWithAuthCode`, {
      sessionid: sessionid.value,
    });
  },
  /* MP0075 获取授权码详情 */
  getAuthCodeDetail(staffId: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/authcode/getAuthCodeDetail`, {
      sessionid: sessionid.value,
      staffId,
    });
  },
  /* MP0044 授权码维护 */
  refreshAuthcode(staffId: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/authcode/refresh`, {
      sessionid: sessionid.value,
      staffId,
    });
  },
  /* MP0076 消息推送订单查询  */
  getOrderInfo(sysSeqNum: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/order/getOrderInfo`, {
      sessionid: sessionid.value,
      sysSeqNum,
    });
  },
  /* MP0079 码牌交易查询  */
  getQrOrders(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/order/qrOrders`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* MP0078 商户门店员工查询 */
  getEmpList(data: any) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(
      `/staff/empList`,
      Object.assign(data, {
        sessionid: sessionid.value,
      })
    );
  },
  /* MP1000 微信认证二维码查询  */
  wxAuthQuery(mchtNo: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/mcht/wxAuthQuery`, {
      sessionid: sessionid.value,
      mchtNo,
    });
  },
  /* MP1001 支付宝认证二维码查询  */
  alAuthQuery(mchtNo: string) {
    const { sessionid } = storeToRefs(useAuthStore());
    return unInstance.post<RESPONSE>(`/mcht/alAuthQuery`, {
      sessionid: sessionid.value,
      mchtNo,
    });
  },
};
